package com.java.sevice;

import com.alibaba.fastjson.JSONObject;
import com.java.dto.ResultMsg;
import com.java.remoteInterface.Bank1Service;
import com.java.remoteInterface.Bank2Service;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
@Slf4j
public class TransferService {
    @Autowired
    Bank1Service bank1Service;
    @Autowired
    Bank2Service bank2Service;

    /**
     * 转账
     */
    @GlobalTransactional
    public ResultMsg transferMoney(Long accountId, BigDecimal amount) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("accountId", accountId);
        jsonObject.put("amount", amount);
        bank1Service.doTransfer(jsonObject);
        bank2Service.doTransfer(jsonObject);
        return ResultMsg.ok("成功");
    }
}